import { config } from '../../config/index';
import request from '../../utils/request';

/** 获取商品列表 */
function mockFetchGood(ID = 0) {
  const { delay } = require('../_utils/delay');
  const { genGood } = require('../../model/good');
  return delay().then(() => genGood(ID));
}

/** 获取商品列表 */
export function fetchGood(ID = 0) {
  if (config.useMock) {
    return mockFetchGood(ID);
  }
  return new Promise((resolve) => {
    resolve('real api');
  });
}

/** 获取商品列表 */
function mockFetchData(ID = 0) {
  const { delay } = require('../_utils/delay');
  const { genData } = require('../../model/data');
  return delay().then(() => genData(ID));
}

/** 拍卖详情 */
export function fetchData(id) {
  // if (config.useMock) {
  //   return mockFetchData(id);
  // }

  return new Promise((resolve) => {
    var url = "/car/user/dealer/detailData?id=" + id;
    request.post(url, null, function (res) {
      if (res.code == 0) {
        resolve(res.data);
      } else {
        resolve({});
      }
    })
  });
}

/**是否缴纳保证金 */
export function checkAuctionMoney(auctionId) {
  return new Promise((resolve) => {
    var url = "/car/user/dealer/checkAuctionMoney?auctionId=" + auctionId + "&type=1";
    request.post(url, null, function (res) {
      if (res.code == 0) {
        resolve(1);
      } else {
        resolve(0);
      }
    })
  });
}
